package com.ebeitech.doorapp.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by alice on 2017/10/24.
 */
public abstract class DBSQLiteOpenHelper extends SQLiteOpenHelper {

	private Class<?>[] modelClasses;

	public DBSQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, Class<?>[] modelClasses) {
		super(context, name, factory, version);
		this.modelClasses = modelClasses;
		Log.e("","init DB:"+name + " version:" + version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		Log.e("DBSQLiteHelper","onCreate DB");
		DBOperateSQLiteHelper.createTablesByClasses(db, modelClasses);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.e("DBSQLiteHelper","onUpgrade oldVersion:" + oldVersion + " newVersion:" + newVersion);
		onCreate(db);
		DBOperateSQLiteHelper.createColumnByClasses(db, modelClasses);
	}
}
